class Test extends Scene {
	// 答题场景
	private  items:any;
	private  itemLabel: eui.Label;
	private  itemA: eui.RadioButton;
	private  itemB: eui.RadioButton;
	private  itemC: eui.RadioButton;
	private  itemD: eui.RadioButton;
	private  btnPre: eui.Button;
	private  btnNext: eui.Button;
	private  index:number = 0;
	private  wrong:number ;
	private  correct:number ;  // 对的题目
	private  no:number ; 
	private  music:eui.Button ;

	public constructor() {
		super()
		this.skinName ="resource/eui_skins/myskins/TestExam.exml"
	}
	protected partAdded(partName:string , instance:any):void{
		super.partAdded(partName , instance);
	}
	protected childrenCreated():void{
		super.childrenCreated();
		// this.addEventListener(egret.Event.ENTER_FRAME , this.rotateLogo , this);
		this.addEventListener(egret.Event.ADDED_TO_STAGE , this.onAddToStage ,this);
		this.init();
	}
	// 初始化
	private init():void{
		// 重置音乐按钮
		// this.music.rotation = MusicManager.Instance.getRotate();
		QuestionManager.Instance.reset();
		this.items = QuestionManager.Instance.GetQuestion();
		console.log('显示题目' , this.items );
		this.showQuestion();
		//监听 上一题按钮
		this.btnPre.addEventListener(egret.TouchEvent.TOUCH_TAP , this.onPreClick ,this);
		//监听 下一题按钮
		this.btnNext.addEventListener(egret.TouchEvent.TOUCH_TAP , this.onNextClick , this );
		//监听  点击选项按钮
		this.itemA.addEventListener(egret.TouchEvent.TOUCH_TAP , (e:egret.TouchEvent)=>{
			this.items[this.index].result = this.itemA.value;
		},this );
		this.itemB.addEventListener(egret.TouchEvent.TOUCH_TAP , (e:egret.TouchEvent)=>{
			this.items[this.index].result = this.itemB.value;
		},this );
		this.itemC.addEventListener(egret.TouchEvent.TOUCH_TAP , (e:egret.TouchEvent)=>{
			this.items[this.index].result = this.itemC.value;
		},this );
		this.itemD.addEventListener(egret.TouchEvent.TOUCH_TAP , (e:egret.TouchEvent)=>{
			this.items[this.index].result = this.itemD.value;
		},this );
		// this.music.addEventListener(egret.TouchEvent.TOUCH_TAP , (e:egret.TouchEvent)=>{
		// 	MusicManager.Instance.onTouch();
		// },this)
	}

	private onAddToStage(event:egret.Event){
		console.log("saaaa")
	}
	// 上一题按钮
	private onPreClick(e:egret.TouchEvent):void{
		this.btnPre.enabled = true;
		this.btnNext.enabled = true;
		if(this.index >0){
			this.index--;
		}else{
			this.btnPre.enabled = false;
		}
		this.showQuestion();
	}
	// 下一题按钮
	private onNextClick(e:egret.TouchEvent):void{
		console.log(88888);
		
		this.btnPre.enabled = true;
		this.btnNext.enabled = true;
		if(this.index < this.items.length-1){
			this.index++;
		}else{
			this.btnNext.enabled = false;
			// this.endTest();
			SceneManager.Instance.changeScene(new EndScene());
		}
		this.showQuestion()
	}
	// 初始化单个题目
	private showQuestion():void{
		let idx = this.index;
		
		this.itemLabel.text = this.items[idx].title;
		this.itemA.label = this.items[idx].a
		this.itemB.label = this.items[idx].b
		this.itemC.label = this.items[idx].c
		this.itemD.label = this.items[idx].d
		this.itemA.selected = false;
		this.itemB.selected = false;
		this.itemC.selected = false;
		this.itemD.selected = false;
		if(this.items[idx].result == 'A'){
			this.itemA.selected = true;
		}else if(this.items[idx].result == 'B'){
			this.itemB.selected = true;
		}else if(this.items[idx].result == 'C'){
			this.itemC.selected = true;
		}else if(this.items[idx].result == 'D'){
			this.itemD.selected = true;
		}
	}
	private rotateLogo(){
		if(this.music){
			this.music.rotation = MusicManager.Instance.getRotate();
		}
	}
}